package com.zb.vo;

import com.zb.annotation.NumberPattern;
import com.zb.entity.ZjStoreSet;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Arrays;
import java.util.Date;

/**
 * @Author WEN
 * @Date 2023/7/26 0026
 **/
@Data
@ApiModel("仓库设置实体封装")
public class StoreSetVo {
    @NotNull(message = "仓库设置ID不能为空")
    @ApiModelProperty(value = "仓库设置ID，必传", required = true, example = "")
    private Long id;

    @NotBlank(message = "出库编码前缀不能为空！")
    @Length(max = 2, message = "出库编码前缀字符长度限制2个以内")
    @Pattern(regexp = "^[A-Za-z1-9]{1,2}$", message = "出库编码前缀不支持输入中文")
    @ApiModelProperty(value = "出库编码前缀", required = true, example = "CK")
    private String outboundCodePrefix;

    @NotBlank(message = "入库编码前缀不能为空！")
    @Length(max = 2, message = "入库编码前缀字符长度限制2个以内")
    @Pattern(regexp = "^[A-Za-z1-9]{1,2}$", message = "入库编码前缀不支持输入中文")
    @ApiModelProperty(value = "入库编码前缀", required = true, example = "RK")
    private String inboundCodePrefix;

    @NotNull(message = "一物一码激活方式不能为空")
    @NumberPattern(regexp = "^[1|2|3]$", required = true, message = "一物一码激活方式参数错误")
    @ApiModelProperty(value = "一物一码激活方式：1-客户登录并激活，2-出库激活并质保，3-出库激活")
    private Integer codeActiveMode;

    @ApiModelProperty(value = "创建时间", hidden = true)
    private Date createTime;

    @ApiModelProperty(value = "更新时间", hidden = true)
    private Date updateTime;

    public static StoreSetVo beanToVo(ZjStoreSet storeSet) {
        StoreSetVo vo = new StoreSetVo();
        BeanUtils.copyProperties(storeSet, vo);
        vo.setCreateTime(storeSet.getGmtCreate());
        vo.setUpdateTime(storeSet.getGmtUpdate());
        return vo;
    }

    public static ZjStoreSet voToBean(StoreSetVo vo) {
        ZjStoreSet storeSet = new ZjStoreSet();
        BeanUtils.copyProperties(vo, storeSet);
        return storeSet;
    }


}
